package com.example.zhihuhelpapp.adapter;

import android.content.Context;
import android.widget.TextView;

import com.example.zhihuhelpapp.R;
import com.example.zhihuhelpapp.bean.JDOrderResult;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

import androidx.core.content.ContextCompat;

public class OrderListAdapter extends CommonAdapter<JDOrderResult.JdUnionOpenOrderRowQueryResponseBean.JDOrderBean.DataBean> {
    public OrderListAdapter(Context context, List<JDOrderResult.JdUnionOpenOrderRowQueryResponseBean.JDOrderBean.DataBean> datas) {
        super(context, R.layout.item_order_list, datas);
    }

    @Override
    protected void convert(ViewHolder holder, JDOrderResult.JdUnionOpenOrderRowQueryResponseBean.JDOrderBean.DataBean dataBean, int position) {
        holder.setText(R.id.tv_order_name, mContext.getString(R.string.order_list_order_name, dataBean.getSkuName()));
        holder.setText(R.id.tv_order_price, mContext.getString(R.string.order_list_order_price, String.valueOf(dataBean.getEstimateCosPrice())));
        holder.setText(R.id.tv_order_count, mContext.getString(R.string.order_list_order_count, dataBean.getSkuNum()));
        holder.setText(R.id.tv_order_rate, mContext.getString(R.string.order_list_order_commissionRate, String.valueOf(dataBean.getCommissionRate())));
        holder.setText(R.id.tv_order_estimate_fee, mContext.getString(R.string.order_list_order_estimateFee, String.valueOf(dataBean.getEstimateFeeAct())));
        holder.setText(R.id.tv_order_id, mContext.getString(R.string.order_list_order_id, String.valueOf(dataBean.getParentId())));
        TextView tv_order_state = holder.getView(R.id.tv_order_state);
        TextView tv_order_time = holder.getView(R.id.tv_order_time);
        tv_order_time.setText(mContext.getString(R.string.order_list_order_time, dataBean.getOrderTime()));

        if (dataBean.isValidOrder()) {
            tv_order_state.setTextColor(ContextCompat.getColor(mContext, R.color.global_text_color));
            tv_order_state.setText(mContext.getString(R.string.order_list_order_state, mContext.getString(R.string.order_list_order_state_normal)));
        } else {
            tv_order_state.setTextColor(ContextCompat.getColor(mContext, R.color.red));
            tv_order_state.setText(mContext.getString(R.string.order_list_order_state, dataBean.getOrderStateStr()));
        }
    }
}
